package com.fm.webrtc.websocket.message.transport;


import com.fm.mediasoup.sdp.Fingerprint;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class DtlsParameters {
    public Fingerprints[] fingerprints;
    public String role;


    public DtlsParameters(){

    }

    public DtlsParameters(Builder builder) {
        fingerprints = builder.fingerprints;
        role = builder.role;
    }

    @Override
    public String toString() {
        return "DtlsParameters{" +
                "fingerprints=" + Arrays.toString(fingerprints) +
                ", role='" + role + '\'' +
                '}';
    }

    public static class Builder {
        public Builder setFingerprints(List<Fingerprint> fingerprintList) {
            List<Fingerprints> fingerprintsList = new ArrayList<>();
            for (Fingerprint fingerprint: fingerprintList) {
                Fingerprints fingerprints = new Fingerprints();
                fingerprints.algorithm = fingerprint.type;
                fingerprints.value = fingerprint.hash;
                fingerprintsList.add(fingerprints);
                break;
            }
            this.fingerprints = new Fingerprints[fingerprintsList.size()];
            fingerprintsList.toArray(this.fingerprints);
            return this;
        }

        public Builder setRole(String role) {
            this.role = role;
            return this;
        }

        private Fingerprints[] fingerprints;
        private String role;

        public DtlsParameters build(){
            return new DtlsParameters(this);
        }
    }



}
